package tech.cn.note.word.fun;

import java.time.LocalDate;

import com.deepoove.poi.render.compute.RenderDataCompute;
import tech.cn.note.utils.DateTimeUtils;

import org.springframework.stereotype.Service;

import static org.springframework.util.ObjectUtils.isEmpty;

@Service
public class Brackets implements RenderFunction {
    /**
     * @param fields            参数1 日期
     * @param renderDataCompute
     * @return
     */
    @Override
    public String doCalculate(String[] fields, RenderDataCompute renderDataCompute) {
        if (isEmpty(fields)) {
            return "";
        }
        String placeHolder = fields[0];
        Object date = renderDataCompute.compute(placeHolder);
        if (date == null) {
            return "";
        }
        return buildDateFormat(DateTimeUtils.toLocalDate(date));
    }

    private String buildDateFormat(LocalDate ld) {
        return "【" + ld.getYear() + "】年【" + ld.getMonthValue() + "】月【" + ld.getDayOfMonth() + "】日";
    }
}
